package scenic.filter;

/**
 * Cubic filter kernel.
 */
public class CubicKernel extends SeparableKernel {
	private double b;
	private double c;
	
	public CubicKernel(double b, double c) {
		this.b = b;
		this.c = c;
	}
	
	public double getValue(double t) {
		double a;
		
		t = Math.abs(t * 4.0);
		
		if(t <= 1.0) {
			a = (12.0 - 9.0 * b - 6.0 * c) * t * t * t + 
				(-18.0 + 12.0 * b + 6.0 * c) * t * t + (6.0 - 2.0 * b);
		} else if(t <= 2.0) {
			a = (-b - 6.0 * c) * t * t * t + (6.0 * b + 30.0 * c) * t * t +
				(-12.0 * b - 48.0 * c) * t + (8.0 * b + 24.0 * c);
		} else {
			a = 0.0;
		}
		
		return a / 6.0 * 4.0;
	}
}
